package game.assist.diablo3.adapter;

import game.assist.diablo3.R;
import game.assist.diablo3.data.vo.NPC;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NpcAdapter extends BaseAdapter {
	private Context context;
	private List<NPC> npcs;
	
	public NpcAdapter(Context context, List<NPC> npcs) {
		this.context = context;
		this.npcs = npcs;
	}

	@Override
	public int getCount() {
		if(npcs==null||npcs.size()==0)
			return 0;
		else
			return npcs.size();
	}

	@Override
	public Object getItem(int position) {
		return npcs.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		NPCHolder holder;
		if(convertView == null) {
			convertView  = LayoutInflater.from(context).inflate(R.layout.npc_item, null);
			holder = new NPCHolder();
			holder.icon  = (ImageView) convertView.findViewById(R.id.npc_item_iv);
			holder.name  = (TextView) convertView.findViewById(R.id.npc_item_tv);
			holder.info = (TextView) convertView.findViewById(R.id.npc_item_tv2);
			convertView.setTag(holder);
		}else {
			holder = (NPCHolder) convertView.getTag();
		}
		holder.icon.setImageResource(npcs.get(position).getIconID());
		holder.name.setText(npcs.get(position).getName());
		holder.info.setText(npcs.get(position).getInfo());
		return convertView;
	}
	
	class NPCHolder {
		ImageView icon;
		TextView name;
		TextView info;
	}

}
